<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Awesome Mac OS Command Line - 早起的年轻人</title>
    <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="早起的年轻人" /><meta name="description" content="awesome-macos-command-line 的中文翻译，翻译不妥的地方，欢迎提 issue 或者 pull request 。 翻译本教程，见识了许多没用过的终端命令，加深了对 Mac 的认识。 精心为 OS X 挑选的 shell 命令和工具。 “你" /><meta name="keywords" content="管理, Github, Vue, flutter, Go" />






<meta name="generator" content="Hugo 0.79.1 with even 4.0.0" />


<link rel="canonical" href="https://luckly.work/post/awesome-macos-command-line-zh/README/" />
<link href="/post/awesome-macos-command-line-zh/README/" rel="alternate" type="application/rss+xml" title="早起的年轻人" />
<link href="/post/awesome-macos-command-line-zh/README/" rel="feed" type="application/rss+xml" title="早起的年轻人" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<link href="/dist/even.06658218.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">
<link rel="stylesheet" href="/css/reset-even.css">


<meta property="og:title" content="Awesome Mac OS Command Line" />
<meta property="og:description" content="awesome-macos-command-line 的中文翻译，翻译不妥的地方，欢迎提 issue 或者 pull request 。 翻译本教程，见识了许多没用过的终端命令，加深了对 Mac 的认识。 精心为 OS X 挑选的 shell 命令和工具。 “你" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://luckly.work/post/awesome-macos-command-line-zh/README/" />
<meta property="article:published_time" content="2019-05-01T14:25:24+08:00" />
<meta property="article:modified_time" content="2019-05-01T14:25:24+08:00" />
<meta itemprop="name" content="Awesome Mac OS Command Line">
<meta itemprop="description" content="awesome-macos-command-line 的中文翻译，翻译不妥的地方，欢迎提 issue 或者 pull request 。 翻译本教程，见识了许多没用过的终端命令，加深了对 Mac 的认识。 精心为 OS X 挑选的 shell 命令和工具。 “你">
<meta itemprop="datePublished" content="2019-05-01T14:25:24+08:00" />
<meta itemprop="dateModified" content="2019-05-01T14:25:24+08:00" />
<meta itemprop="wordCount" content="8844">



<meta itemprop="keywords" content="Awesome," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Awesome Mac OS Command Line"/>
<meta name="twitter:description" content="awesome-macos-command-line 的中文翻译，翻译不妥的地方，欢迎提 issue 或者 pull request 。 翻译本教程，见识了许多没用过的终端命令，加深了对 Mac 的认识。 精心为 OS X 挑选的 shell 命令和工具。 “你"/>

</head>
<body>
<div id="mobile-navbar" class="mobile-navbar">
    <div class="mobile-header-logo">
        <a href="/" class="logo">早起的年轻人</a>
    </div>
    <div class="mobile-navbar-icon">
        <span></span>
        <span></span>
        <span></span>
    </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
    <ul class="mobile-menu-list">
        <a href="/">
            <li class="mobile-menu-item" title="首页">首页</li>
        </a>
        <a href="/post/">
            <li class="mobile-menu-item" title="归档">归档</li>
        </a>
        <a href="/categories/">
            <li class="mobile-menu-item" title="分类">分类</li>
        </a>
        <a href="/tags/">
            <li class="mobile-menu-item" title="标签">标签</li>
        </a>
        <a href="/about/">
            <li class="mobile-menu-item" title="关于我">关于我</li>
        </a>
        <a href="/friend/">
            <li class="mobile-menu-item" title="友链">友链</li>
        </a>
        <a href="https://github.com/ITmxs/">
            <li class="mobile-menu-item" title="阅读清单">阅读清单</li>
        </a>
        
    </ul>
    <form class="search-form" style="position: absolute;">
    <input name="search" type="search" style="height: 28px;padding-left: 30px;"/>
    <input type="image" src="/img/search.svg" alt="Search" style="position: absolute;left: 6px;top: 6px;"/>
</form>


</nav>

<div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/%20/" class="logo">早起的年轻人</a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
      <a class="menu-item-link" href="/">首页</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/post/">归档</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/categories/">分类</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/tags/">标签</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/about/">关于我</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/friend/">友链</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="https://github.com/ITmxs/">阅读清单</a>
    </li>
  </ul>
</nav>
        <form class="search-form" style="position: absolute;">
    <input name="search" type="search" style="height: 28px;padding-left: 30px;"/>
    <input type="image" src="/img/search.svg" alt="Search" style="position: absolute;left: 6px;top: 6px;"/>
</form>



    </header>


    <main id="main" class="main">
        <div class="content-wrapper">
            <div id="content" class="content">
                <article class="post">
  
  <header class="post-header">
    <h1 class="post-title">Awesome Mac OS Command Line</h1>

    <div class="post-meta">
      <span class="post-time"> 2019-05-01 14:25 </span>
      <div class="post-category">
        <a href="/categories/Mac/"> Mac </a>
        </div>
      <span class="more-meta"> 约 8844 字 </span>
      <span class="more-meta"> 预计阅读 18 分钟 </span>
      <span id="busuanzi_container_page_pv" class="more-meta"> <span id="busuanzi_value_page_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次阅读 </span>
    </div>
  </header>

  <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#外形">外形</a>
          <ul>
            <li><a href="#透明度">透明度</a></li>
            <li><a href="#桌面背景">桌面背景</a></li>
          </ul>
        </li>
        <li><a href="#应用">应用</a>
          <ul>
            <li><a href="#app-store">App Store</a></li>
            <li><a href="#苹果远程桌面">苹果远程桌面</a></li>
            <li><a href="#通讯录">通讯录</a></li>
            <li><a href="#google">Google</a></li>
            <li><a href="#itunes">iTunes</a></li>
            <li><a href="#邮件">邮件</a></li>
            <li><a href="#safari">Safari</a></li>
            <li><a href="#sketch">Sketch</a></li>
            <li><a href="#skim">Skim</a></li>
            <li><a href="#终端">终端</a></li>
            <li><a href="#文本编辑">文本编辑</a></li>
            <li><a href="#visual-studio-code">Visual Studio Code</a></li>
          </ul>
        </li>
        <li><a href="#备份">备份</a>
          <ul>
            <li><a href="#时间机器">时间机器</a></li>
          </ul>
        </li>
        <li><a href="#开发者">开发者</a>
          <ul>
            <li><a href="#vim">Vim</a></li>
            <li><a href="#xcode">Xcode</a></li>
          </ul>
        </li>
        <li><a href="#程序坞">程序坞</a>
          <ul>
            <li></li>
          </ul>
        </li>
        <li><a href="#文档">文档</a>
          <ul>
            <li></li>
          </ul>
        </li>
        <li><a href="#文件磁盘和卷">文件、磁盘和卷</a>
          <ul>
            <li></li>
            <li><a href="#apfs">APFS</a></li>
            <li><a href="#磁盘映像">磁盘映像</a></li>
          </ul>
        </li>
        <li><a href="#访达">访达</a>
          <ul>
            <li><a href="#桌面">桌面</a></li>
            <li><a href="#文件和文件夹">文件和文件夹</a></li>
            <li><a href="#布局">布局</a></li>
            <li><a href="#元数据文件">元数据文件</a></li>
            <li><a href="#打开文件">打开文件</a></li>
          </ul>
        </li>
        <li><a href="#字体">字体</a>
          <ul>
            <li></li>
          </ul>
        </li>
        <li><a href="#函数">函数</a></li>
        <li><a href="#硬件">硬件</a>
          <ul>
            <li><a href="#蓝牙">蓝牙</a></li>
            <li><a href="#硬盘">硬盘</a></li>
            <li><a href="#硬件信息">硬件信息</a></li>
            <li><a href="#红外传感器">红外传感器</a></li>
            <li><a href="#电池管理">电池管理</a></li>
          </ul>
        </li>
        <li><a href="#输入设备">输入设备</a>
          <ul>
            <li><a href="#键盘">键盘</a></li>
          </ul>
        </li>
        <li><a href="#启动台">启动台</a>
          <ul>
            <li></li>
          </ul>
        </li>
        <li><a href="#媒体">媒体</a>
          <ul>
            <li><a href="#音频">音频</a></li>
            <li><a href="#视频">视频</a></li>
          </ul>
        </li>
        <li><a href="#网络">网络</a>
          <ul>
            <li><a href="#bonjour">Bonjour</a></li>
            <li><a href="#dhcp">DHCP</a></li>
            <li><a href="#dns">DNS</a></li>
            <li><a href="#域名">域名</a></li>
            <li><a href="#网络设置">网络设置</a></li>
            <li><a href="#网络工具">网络工具</a></li>
            <li><a href="#ssh">SSH</a></li>
            <li><a href="#tcpip">TCP/IP</a></li>
            <li><a href="#tftp">TFTP</a></li>
            <li><a href="#wi-fi">Wi-Fi</a></li>
          </ul>
        </li>
        <li><a href="#包管理器">包管理器</a></li>
        <li><a href="#打印">打印</a>
          <ul>
            <li></li>
          </ul>
        </li>
        <li><a href="#安全">安全</a>
          <ul>
            <li><a href="#应用防火墙">应用防火墙</a></li>
            <li><a href="#网关">网关</a></li>
            <li><a href="#密码">密码</a></li>
            <li><a href="#物理访问">物理访问</a></li>
            <li><a href="#擦除数据">擦除数据</a></li>
          </ul>
        </li>
        <li><a href="#搜索">搜索</a>
          <ul>
            <li><a href="#查找">查找</a></li>
            <li><a href="#定位">定位</a></li>
          </ul>
        </li>
        <li><a href="#系统">系统</a>
          <ul>
            <li><a href="#airdrop">AirDrop</a></li>
            <li><a href="#applescript">AppleScript</a></li>
            <li><a href="#基础">基础</a></li>
            <li><a href="#剪贴板">剪贴板</a></li>
            <li><a href="#文件库">文件库</a></li>
            <li><a href="#信息报告">信息/报告</a></li>
            <li><a href="#安装系统">安装系统</a></li>
            <li><a href="#内核扩展">内核扩展</a></li>
            <li><a href="#自启动服务">自启动服务</a></li>
            <li><a href="#自启动服务-1">自启动服务</a></li>
            <li><a href="#登录窗口">登录窗口</a></li>
            <li><a href="#内存管理">内存管理</a></li>
            <li><a href="#通知中心">通知中心</a></li>
            <li><a href="#快速浏览">快速浏览</a></li>
            <li><a href="#远程苹果事件">远程苹果事件</a></li>
            <li><a href="#root-用户">Root 用户</a></li>
            <li><a href="#安全模式启动">安全模式启动</a></li>
            <li><a href="#截图">截图</a></li>
            <li><a href="#软件安装">软件安装</a></li>
            <li><a href="#软件更新">软件更新</a></li>
            <li><a href="#软件版本">软件版本</a></li>
            <li><a href="#聚焦">聚焦</a></li>
            <li><a href="#系统完整性保护">系统完整性保护</a></li>
            <li><a href="#时间和日期">时间和日期</a></li>
          </ul>
        </li>
        <li><a href="#终端-1">终端</a>
          <ul>
            <li></li>
            <li><a href="#替代终端">替代终端</a></li>
            <li><a href="#shells">Shells</a></li>
            <li><a href="#终端字体">终端字体</a></li>
          </ul>
        </li>
        <li><a href="#词汇表">词汇表</a>
          <ul>
            <li><a href="#mac-os-xos-x-以及-macos-的版本信息">Mac OS X、OS X 以及 macOS 的版本信息</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
  <div class="post-outdated">
    <div class="warn">
      <p>【注意】最后更新于 <span class="timeago" datetime="2019-05-01T14:25:24" title="May 1, 2019">May 1, 2019</span>，文中内容可能已过时，请谨慎使用。</p>
    </div>
  </div>
  <div class="post-content">
    <p><a href="https://github.com/sindresorhus/awesome"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome"></a><a href="https://travis-ci.org/nusr/awesome-macos-command-line-zh"><img src="https://travis-ci.org/nusr/awesome-macos-command-line-zh.svg?branch=master" alt="Build Status"></a></p>
<p><a href="https://github.com/herrbischoff/awesome-macos-command-line">awesome-macos-command-line</a> 的中文翻译，翻译不妥的地方，欢迎提 issue 或者 pull request 。</p>
<p>翻译本教程，见识了许多没用过的终端命令，加深了对 Mac 的认识。</p>
<blockquote>
<p>精心为 OS X 挑选的 shell 命令和工具。</p>
<p><em>“你无需知晓一切。仅仅在你需要的时候，找到它就行了。” (John Brunner)</em></p>
</blockquote>
<p>更多好用的终端工具，请参阅原作者的姐妹项目 <a href="https://github.com/herrbischoff/awesome-command-line-apps">Awesome Command Line Apps</a>。</p>
<p>中文 | <a href="https://github.com/herrbischoff/awesome-macos-command-line">English</a></p>
<h2 id="外形">外形</h2>
<h3 id="透明度">透明度</h3>
<h4 id="菜单和窗口的透明度设置">菜单和窗口的透明度设置</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 减小透明度</span>
defaults write com.apple.universalaccess reduceTransparency -bool <span class="nb">true</span>

<span class="c1"># 恢复默认透明度</span>
defaults write com.apple.universalaccess reduceTransparency -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="桌面背景">桌面背景</h3>
<h4 id="设置桌面背景">设置桌面背景</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># Mountain Lion 及之前的版本支持</span>
osascript -e <span class="s1">&#39;tell application &#34;Finder&#34; to set desktop picture to POSIX file &#34;/path/to/picture.jpg&#34;&#39;</span>

<span class="c1"># 从 Mavericks 开始支持</span>
sqlite3 ~/Library/Application<span class="se">\ </span>Support/Dock/desktoppicture.db <span class="s2">&#34;update data set value = &#39;/path/to/picture.jpg&#39;&#34;</span> <span class="o">&amp;&amp;</span> killall Dock
</code></pre></td></tr></table>
</div>
</div><h2 id="应用">应用</h2>
<h3 id="app-store">App Store</h3>
<h4 id="列出所有从-app-store-下载的应用">列出所有从 App Store 下载的应用</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 通过 find</span>
find /Applications -path <span class="s1">&#39;*Contents/_MASReceipt/receipt&#39;</span> -maxdepth <span class="m">4</span> -print <span class="p">|</span><span class="se">\s</span>ed <span class="s1">&#39;s#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##&#39;</span>

<span class="c1"># 通过 Spotlight</span>
mdfind <span class="nv">kMDItemAppStoreHasReceipt</span><span class="o">=</span><span class="m">1</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示调试菜单">显示调试菜单</h4>
<p>Yosemite 版本起作用</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.appstore ShowDebugMenu -bool <span class="nb">true</span>

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.appstore ShowDebugMenu -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="苹果远程桌面">苹果远程桌面</h3>
<h4 id="唤醒手册">唤醒手册</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help
</code></pre></td></tr></table>
</div>
</div><h4 id="唤醒和睡眠-ard-agent-和-helper">唤醒和睡眠 ARD Agent 和 Helper</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 激活并且重启 ARD Agent 和 Helper</span>
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -restart -agent -console

<span class="c1"># 睡眠并且停止远程管理服务</span>
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop
</code></pre></td></tr></table>
</div>
</div><h4 id="开启和关闭远程桌面共享">开启和关闭远程桌面共享</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 给予所有用户完全的接入权限</span>
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all

<span class="c1"># 关闭 ARD Agent 和删除所有用户的接入权限</span>
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off
</code></pre></td></tr></table>
</div>
</div><h4 id="删除苹果远程桌面设置">删除苹果远程桌面设置</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo rm -rf /var/db/RemoteManagement <span class="p">;</span> <span class="se">\
</span><span class="se"></span>sudo defaults delete /Library/Preferences/com.apple.RemoteDesktop.plist <span class="p">;</span> <span class="se">\
</span><span class="se"></span>defaults delete ~/Library/Preferences/com.apple.RemoteDesktop.plist <span class="p">;</span> <span class="se">\
</span><span class="se"></span>sudo rm -r /Library/Application<span class="se">\ </span>Support/Apple/Remote<span class="se">\ </span>Desktop/ <span class="p">;</span> <span class="se">\
</span><span class="se"></span>rm -r ~/Library/Application<span class="se">\ </span>Support/Remote<span class="se">\ </span>Desktop/ <span class="p">;</span> <span class="se">\
</span><span class="se"></span>rm -r ~/Library/Containers/com.apple.RemoteDesktop
</code></pre></td></tr></table>
</div>
</div><h3 id="通讯录">通讯录</h3>
<h4 id="调试模式">调试模式</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.addressbook ABShowDebugMenu -bool <span class="nb">true</span>

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.addressbook ABShowDebugMenu -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="google">Google</h3>
<h4 id="卸载-google-更新">卸载 Google 更新</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/ksinstall --nuke
</code></pre></td></tr></table>
</div>
</div><h3 id="itunes">iTunes</h3>
<h4 id="键盘媒体健">键盘媒体健</h4>
<p>Yosemite 版本起作用。从 El Capitan 开始引入了系统完整性保护，可防止系统启动代理被卸载。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 停止响应按键</span>
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist

<span class="c1"># 响应按键 (默认)</span>
launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist
</code></pre></td></tr></table>
</div>
</div><p>从 El Capitan 开始，您可以禁用 SIP 或者使用某种黑客手段，这将使任何用户都无法访问 iTunes，从而有效地阻止它自己和它的帮助者启动。 请注意，这将无法安装 iTunes ，并可能与操作系统的更新相冲突。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo chmod <span class="m">0000</span> /Applications/iTunes.app
</code></pre></td></tr></table>
</div>
</div><h3 id="邮件">邮件</h3>
<h4 id="将附件显示为图标">将附件显示为图标</h4>
<p>Mac 10.14.4 测试，纯文本或其他文件会显示为图标，但是图片会直接插入。图片可以右键转换为图标，或者更换邮箱客户端解决。<a href="https://github.com/nusr/awesome-macos-command-line-zh/issues/1">issue 1</a></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
</code></pre></td></tr></table>
</div>
</div><h4 id="清空邮件索引">清空邮件索引</h4>
<p>下面的 AppleScript 代码将关闭邮件，清空 SQLite 索引，然后重新打开 Mail。在一个没有优化的大型电子邮件数据库中，可以显着提高响应速度。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-applescript" data-lang="applescript"><span class="cm">(*
</span><span class="cm">加快邮件索引。
</span><span class="cm">代码来源: http://web.archive.org/web/20071008123746/http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/
</span><span class="cm">最初由 pmbuko 改编，Romulo 修改。Brett Terpstra 在 2012 年更新，Mathias Törnblom 在 2013 更新到 V3 支持 El Capitan。Andrei Miclaus 在 2017 年更新到 V4,支持 Sierra。
</span><span class="cm">*)</span>

<span class="k">tell</span> <span class="nb">application</span> <span class="s2">&#34;Mail&#34;</span> <span class="k">to</span> <span class="nb">quit</span>
<span class="k">set</span> <span class="nv">os_version</span> <span class="k">to</span> <span class="nb">do shell script</span> <span class="s2">&#34;sw_vers -productVersion&#34;</span>
<span class="k">set</span> <span class="nv">mail_version</span> <span class="k">to</span> <span class="s2">&#34;V2&#34;</span>
<span class="k">considering </span><span class="nb">numeric strings</span>
    <span class="k">if</span> <span class="s2">&#34;10.10&#34;</span> <span class="o">&lt;=</span> <span class="nv">os_version</span> <span class="k">then</span> <span class="k">set</span> <span class="nv">mail_version</span> <span class="k">to</span> <span class="s2">&#34;V3&#34;</span>
    <span class="k">if</span> <span class="s2">&#34;10.12&#34;</span> <span class="o">&lt;=</span> <span class="nv">os_version</span> <span class="k">then</span> <span class="k">set</span> <span class="nv">mail_version</span> <span class="k">to</span> <span class="s2">&#34;V4&#34;</span>
    <span class="k">if</span> <span class="s2">&#34;10.13&#34;</span> <span class="o">&lt;=</span> <span class="nv">os_version</span> <span class="k">then</span> <span class="k">set</span> <span class="nv">mail_version</span> <span class="k">to</span> <span class="s2">&#34;V5&#34;</span>
    <span class="k">if</span> <span class="s2">&#34;10.14&#34;</span> <span class="o">&lt;=</span> <span class="nv">os_version</span> <span class="k">then</span> <span class="k">set</span> <span class="nv">mail_version</span> <span class="k">to</span> <span class="s2">&#34;V6&#34;</span>
<span class="k">end</span> <span class="k">considering</span>

<span class="k">set</span> <span class="nv">sizeBefore</span> <span class="k">to</span> <span class="nb">do shell script</span> <span class="s2">&#34;ls -lnah ~/Library/Mail/&#34;</span> <span class="o">&amp;</span> <span class="nv">mail_version</span> <span class="o">&amp;</span> <span class="s2">&#34;/MailData | grep -E &#39;Envelope Index$&#39; | awk {&#39;print $5&#39;}&#34;</span>
<span class="nb">do shell script</span> <span class="s2">&#34;/usr/bin/sqlite3 ~/Library/Mail/&#34;</span> <span class="o">&amp;</span> <span class="nv">mail_version</span> <span class="o">&amp;</span> <span class="s2">&#34;/MailData/Envelope\\ Index vacuum&#34;</span>

<span class="k">set</span> <span class="nv">sizeAfter</span> <span class="k">to</span> <span class="nb">do shell script</span> <span class="s2">&#34;ls -lnah ~/Library/Mail/&#34;</span> <span class="o">&amp;</span> <span class="nv">mail_version</span> <span class="o">&amp;</span> <span class="s2">&#34;/MailData | grep -E &#39;Envelope Index$&#39; | awk {&#39;print $5&#39;}&#34;</span>

<span class="nb">display dialog</span> <span class="p">(</span><span class="s2">&#34;Mail index before: &#34;</span> <span class="o">&amp;</span> <span class="nv">sizeBefore</span> <span class="o">&amp;</span> <span class="no">return</span> <span class="o">&amp;</span> <span class="s2">&#34;Mail index after: &#34;</span> <span class="o">&amp;</span> <span class="nv">sizeAfter</span> <span class="o">&amp;</span> <span class="no">return</span> <span class="o">&amp;</span> <span class="no">return</span> <span class="o">&amp;</span> <span class="s2">&#34;Enjoy the new speed!&#34;</span><span class="p">)</span>

<span class="k">tell</span> <span class="nb">application</span> <span class="s2">&#34;Mail&#34;</span> <span class="k">to</span> <span class="nb">activate</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="safari">Safari</h3>
<h4 id="改变默认字体">改变默认字体</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2StandardFontFamily Georgia
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFontSize <span class="m">16</span>
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2FixedFontFamily Menlo
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFixedFontSize <span class="m">14</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="开启开发者菜单以及网络检查">开启开发者菜单以及网络检查</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.Safari IncludeInternalDebugMenu -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.Safari IncludeDevelopMenu -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write -g WebKitDeveloperExtras -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="获取当前网页数据">获取当前网页数据</h4>
<p>其他选项: <code>get source</code>, <code>get text</code>.</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">osascript -e <span class="s1">&#39;tell application &#34;Safari&#34; to get URL of current tab of front window&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="使用-backspacedelete-返回上一页">使用 Backspace/Delete 返回上一页</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool YES

<span class="c1"># 关闭</span>
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool NO
</code></pre></td></tr></table>
</div>
</div><h3 id="sketch">Sketch</h3>
<h4 id="导出压缩-svg">导出压缩 SVG</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
</code></pre></td></tr></table>
</div>
</div><h3 id="skim">Skim</h3>
<h4 id="关闭自动加载弹窗">关闭自动加载弹窗</h4>
<p>去掉弹窗并设置默认自动加载</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -app Skim SKAutoReloadFileUpdate -boolean <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="终端">终端</h3>
<h4 id="焦点跟随鼠标">焦点跟随鼠标</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.Terminal FocusFollowsMouse -string YES

<span class="c1"># 关闭</span>
defaults write com.apple.Terminal FocusFollowsMouse -string NO
</code></pre></td></tr></table>
</div>
</div><h3 id="文本编辑">文本编辑</h3>
<h4 id="将文本编辑设置为纯文本的默认打开方式">将文本编辑设置为纯文本的默认打开方式</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.TextEdit RichText -int <span class="m">0</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="visual-studio-code">Visual Studio Code</h3>
<h4 id="解决-vscode-vim-按键重复">解决 VSCode Vim 按键重复</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="备份">备份</h2>
<h3 id="时间机器">时间机器</h3>
<h4 id="改变备份间隔">改变备份间隔</h4>
<p>备份间隔改为 30 分钟，单位是秒。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int <span class="m">1800</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="本地备份">本地备份</h4>
<p>本地备份时，时间机器备份卷不可用。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
defaults <span class="nb">read</span> /Library/Preferences/com.apple.TimeMachine MobileBackups

<span class="c1"># 开启 (默认)</span>
sudo tmutil enablelocal

<span class="c1"># 关闭</span>
sudo tmutil disablelocal
</code></pre></td></tr></table>
</div>
</div><p>从 High Sierra 开始，你无法禁用本地快照。 时间机器始终会创建本地 APFS 快照，并使用该快照作为创建常规备份的数据源，而不是使用活动磁盘作为数据源，就像 HFS 格式化磁盘一样。</p>
<h4 id="防止时间机器提示将新的硬盘启动器作为本分卷">防止时间机器提示将新的硬盘启动器作为本分卷</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo defaults write /Library/Preferences/com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示时间机器的日志">显示时间机器的日志</h4>
<p>这个脚本将输出过去 12 个小时时间机器的备份活动。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="cp">#!/bin/sh
</span><span class="cp"></span>
<span class="nv">filter</span><span class="o">=</span><span class="s1">&#39;processImagePath contains &#34;backupd&#34; and subsystem beginswith &#34;com.apple.TimeMachine&#34;&#39;</span>

<span class="c1"># show the last 12 hours</span>
<span class="nv">start</span><span class="o">=</span><span class="s2">&#34;</span><span class="k">$(</span>date -j -v-12H +<span class="s1">&#39;%Y-%m-%d %H:%M:%S&#39;</span><span class="k">)</span><span class="s2">&#34;</span>

<span class="nb">echo</span> <span class="s2">&#34;&#34;</span>
<span class="nb">echo</span> <span class="s2">&#34;[History (from </span><span class="nv">$start</span><span class="s2">)]&#34;</span>
<span class="nb">echo</span> <span class="s2">&#34;&#34;</span>

log show --style syslog --info --start <span class="s2">&#34;</span><span class="nv">$start</span><span class="s2">&#34;</span> --predicate <span class="s2">&#34;</span><span class="nv">$filter</span><span class="s2">&#34;</span>

<span class="nb">echo</span> <span class="s2">&#34;&#34;</span>
<span class="nb">echo</span> <span class="s2">&#34;[Following]&#34;</span>
<span class="nb">echo</span> <span class="s2">&#34;&#34;</span>

log stream --style syslog --info --predicate <span class="s2">&#34;</span><span class="nv">$filter</span><span class="s2">&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="充电时切换备份">充电时切换备份</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
sudo defaults <span class="nb">read</span> /Library/Preferences/com.apple.TimeMachine RequiresACPower

<span class="c1"># 开启 (默认)</span>
sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool <span class="nb">true</span>

<span class="c1"># 关闭</span>
sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="验证备份">验证备份</h4>
<p>从 OS X 10.11 开始，时间机器记录文件校验和，并且复制到快照。 对于早期版本的 OS X，校验和不会复制到快照。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo tmutil verifychecksums /path/to/backup
</code></pre></td></tr></table>
</div>
</div><h2 id="开发者">开发者</h2>
<h3 id="vim">Vim</h3>
<h4 id="编译-sane-vim">编译 Sane Vim</h4>
<p>通过 Homebrew 编译出完整 Mac Vim，包括覆盖系统的 Vim。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">brew install macvim --HEAD --with-cscope --with-lua --with-override-system-vim --with-luajit --with-python
</code></pre></td></tr></table>
</div>
</div><h4 id="neovim">Neovim</h4>
<p>通过 Homebrew 安装现代化的 Vim 替代品。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">brew install neovim
</code></pre></td></tr></table>
</div>
</div><h3 id="xcode">Xcode</h3>
<h4 id="安装没有命令行工具的-xcode">安装没有命令行工具的 Xcode</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">xcode-select --install
</code></pre></td></tr></table>
</div>
</div><h4 id="删除所有不可用的模拟器">删除所有不可用的模拟器</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">xcrun simctl delete unavailable
</code></pre></td></tr></table>
</div>
</div><h2 id="程序坞">程序坞</h2>
<h4 id="将最近使用的程序添加到程序坞">将最近使用的程序添加到程序坞</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock persistent-others -array-add <span class="s1">&#39;{ &#34;tile-data&#34; = { &#34;list-type&#34; = 1; }; &#34;tile-type&#34; = &#34;recents-tile&#34;; }&#39;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="添加间隔符的无名文件夹">添加间隔符的无名文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock persistent-others -array-add <span class="s1">&#39;{ &#34;tile-data&#34; = {}; &#34;tile-type&#34;=&#34;small-spacer-tile&#34;; }&#39;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="添加空格">添加空格</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock persistent-apps -array-add <span class="s1">&#39;{&#34;tile-type&#34;=&#34;spacer-tile&#34;;}&#39;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="添加小空格">添加小空格</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock persistent-apps -array-add <span class="s1">&#39;{&#34;tile-type&#34;=&#34;small-spacer-tile&#34;;}&#39;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="根据用户最近的使用自动重排">根据用户最近的使用自动重排</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启 (默认)</span>
defaults write com.apple.dock mru-spaces -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭</span>
defaults write com.apple.dock mru-spaces -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="图标弹跳">图标弹跳</h4>
<p>全局设置当唤醒应用时，是否弹跳图标。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启 (默认)</span>
defaults write com.apple.dock no-bouncing -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭</span>
defaults write com.apple.dock no-bouncing -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="锁住程序坞大小">锁住程序坞大小</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.Dock size-immutable -bool yes <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.Dock size-immutable -bool no <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="重置程序坞">重置程序坞</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults delete com.apple.dock <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="改变程序坞大小">改变程序坞大小</h4>
<p>完全改变程序坞主体大小。要调整大小，将 <strong>0</strong> 改为整数</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock tilesize -int <span class="m">0</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="滚动手势">滚动手势</h4>
<p>使用触摸板或鼠标滚轮与程序坞进行交互，允许您使用向上滚动手势打开应用。正在运行的程序也可以使用相同的手势调用程序窗口管理。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.dock scroll-to-open -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.dock scroll-to-open -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="启用自动掩藏">启用自动掩藏</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock autohide -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="设置自动显示和掩藏的延迟时间">设置自动显示和掩藏的延迟时间</h4>
<p>浮点数定义了显示和掩藏的延迟时间(单位毫秒)。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.dock autohide-time-modifier -float 0.4 <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.dock autohide-delay -float <span class="m">0</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="显示掩藏-app-的图标">显示掩藏 APP 的图标</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.dock showhidden -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.dock showhidden -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h4 id="仅显示启动的应用程序图标">仅显示启动的应用程序图标</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.dock static-only -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.dock static-only -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h2 id="文档">文档</h2>
<h4 id="将文件转换为-html">将文件转换为 HTML</h4>
<p>支持的格式有纯文本、富文本(rtf)以及微软的 Word(doc/docx)。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">textutil -convert html file.ext
</code></pre></td></tr></table>
</div>
</div><h2 id="文件磁盘和卷">文件、磁盘和卷</h2>
<h4 id="创建一个空文件">创建一个空文件</h4>
<p>创建一个 10 GB 的空文件。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">mkfile 10g /path/to/file
</code></pre></td></tr></table>
</div>
</div><h4 id="禁止突发动作感应">禁止突发动作感应</h4>
<p>当你使用的是 SSD 时，这个设置是无用的。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo pmset -a sms <span class="m">0</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="弹出所有可安装的卷">弹出所有可安装的卷</h4>
<p>唯一可以向访达发送 AppleScript 命令的方法。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">osascript -e <span class="s1">&#39;tell application &#34;Finder&#34; to eject (every disk whose ejectable is true)&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="修复文件权限">修复文件权限</h4>
<p>不依赖图形化磁盘工具修复文件权限。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo diskutil repairPermissions /
</code></pre></td></tr></table>
</div>
</div><blockquote>
<p>从 OS X El Capitan 开始，系统文件权限将自动受到保护。 不再需要使用磁盘工具验证或修复权限。(<a href="https://support.apple.com/en-us/HT201560">来源</a>)</p>
</blockquote>
<h4 id="设置启动卷">设置启动卷</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># Up to Yosemite</span>
bless --mount <span class="s2">&#34;/path/to/mounted/volume&#34;</span> --setBoot

<span class="c1"># From El Capitan</span>
sudo systemsetup -setstartupdisk /System/Library/CoreServices
</code></pre></td></tr></table>
</div>
</div><h4 id="示所有附加的磁盘和分区">示所有附加的磁盘和分区</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">diskutil list
</code></pre></td></tr></table>
</div>
</div><h4 id="查看文件系统的使用率">查看文件系统的使用率</h4>
<p>连续显示文件使用信息。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo fs_usage
</code></pre></td></tr></table>
</div>
</div><h3 id="apfs">APFS</h3>
<p>从 High Sierra 开启，没有中央程序，并且使用不一致，因为大多数功能都被卷入到 <code>tmutil</code>。</p>
<h4 id="将卷从-hfs-转换为-apfs">将卷从 HFS+ 转换为 APFS</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">/System/Library/Filesystems/apfs.fs/Contents/Resources/hfs_convert /path/to/file/system
</code></pre></td></tr></table>
</div>
</div><h4 id="创建新的-apfs-文件系统">创建新的 APFS 文件系统</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">/System/Library/Filesystems/apfs.fs/Contents/Resources/newfs_apfs /path/to/device
</code></pre></td></tr></table>
</div>
</div><h4 id="创建快照">创建快照</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">tmutil localsnapshot
</code></pre></td></tr></table>
</div>
</div><h4 id="删除快照">删除快照</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">tmutil deletelocalsnapshots com.apple.TimeMachine.2018-01-26-044042
</code></pre></td></tr></table>
</div>
</div><h4 id="列出所有快照">列出所有快照</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">tmutil listlocalsnapshots /
</code></pre></td></tr></table>
</div>
</div><h4 id="挂载快照">挂载快照</h4>
<p>快照是只读的。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">mkdir ~/mnt
/System/Library/Filesystems/apfs.fs/Contents/Resources/mount_apfs -s com.apple.TimeMachine.2018-01-26-044042 / ~/mnt
</code></pre></td></tr></table>
</div>
</div><h3 id="磁盘映像">磁盘映像</h3>
<h4 id="从文件内容创建磁盘映像">从文件内容创建磁盘映像</h4>
<p>将安装的应用程序转换为二进制包。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">hdiutil create -volname <span class="s2">&#34;Volume Name&#34;</span> -srcfolder /path/to/folder -ov diskimage.dmg
</code></pre></td></tr></table>
</div>
</div><p>如果你想加密磁盘映像：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">hdiutil create -encryption -stdinpass -volname <span class="s2">&#34;Volume Name&#34;</span> -srcfolder /path/to/folder -ov encrypted.dmg
</code></pre></td></tr></table>
</div>
</div><p>打包前，你要输入密码。为了直接输入密码不弹窗：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">echo</span> -n YourPassword <span class="p">|</span> hdiutil create -encryption -stdinpass -volname <span class="s2">&#34;Volume Name&#34;</span> -srcfolder /path/to/folder -ov encrypted.dmg
</code></pre></td></tr></table>
</div>
</div><h4 id="将磁盘映像刻录为-dvd">将磁盘映像刻录为 DVD</h4>
<p>这个命令可以应用在 .iso 、.img 和 .dmg 文件上。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">hdiutil burn /path/to/image_file
</code></pre></td></tr></table>
</div>
</div><h4 id="禁止磁盘映像验证">禁止磁盘映像验证</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.frameworks.diskimages skip-verify -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.frameworks.diskimages skip-verify-locked -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.frameworks.diskimages skip-verify-remote -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="制作-os-x-启动卷">制作 OS X 启动卷</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">bless --folder <span class="s2">&#34;/path/to/mounted/volume/System/Library/CoreServices&#34;</span> --bootinfo --bootefi
</code></pre></td></tr></table>
</div>
</div><h4 id="挂载磁盘映像">挂载磁盘映像</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">hdiutil attach /path/to/diskimage.dmg
</code></pre></td></tr></table>
</div>
</div><h4 id="卸载磁盘映像">卸载磁盘映像</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">hdiutil detach /dev/disk2s1
</code></pre></td></tr></table>
</div>
</div><h4 id="将磁盘映像写入到卷中">将磁盘映像写入到卷中</h4>
<p>就像磁盘工具的恢复功能。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo asr -restore -noverify -source /path/to/diskimage.dmg -target /Volumes/VolumeToRestoreTo
</code></pre></td></tr></table>
</div>
</div><h2 id="访达">访达</h2>
<h3 id="桌面">桌面</h3>
<h4 id="显示外部媒体">显示外部媒体</h4>
<p>外部的 HDs 、thumb drives 等等。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h4 id="显示内部媒体">显示内部媒体</h4>
<p>自建的 HDs 或者 SSDs。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h4 id="显示可移动媒体">显示可移动媒体</h4>
<p>CDs 、DVDs 、iPods 等等。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h4 id="显示网络卷">显示网络卷</h4>
<p>AFP 、SMB、 NFS、 WebDAV 等等。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.finder ShowMountedServersOnDesktop -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.finder ShowMountedServersOnDesktop -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h3 id="文件和文件夹">文件和文件夹</h3>
<h4 id="清除所有访问控制列表acls">清除所有访问控制列表(ACLs)</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo chmod -RN /path/to/folder
</code></pre></td></tr></table>
</div>
</div><h4 id="在访达掩藏文件夹">在访达掩藏文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">chflags hidden /path/to/folder/
</code></pre></td></tr></table>
</div>
</div><h4 id="显示所有文件的扩展名">显示所有文件的扩展名</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g AppleShowAllExtensions -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示掩藏文件">显示掩藏文件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 显示所有</span>
defaults write com.apple.finder AppleShowAllFiles <span class="nb">true</span>

<span class="c1"># 恢复文件的默认显示</span>
defaults write com.apple.finder AppleShowAllFiles <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="删除保护标签">删除保护标签</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo chflags -R nouchg /path/to/file/or/folder
</code></pre></td></tr></table>
</div>
</div><h4 id="在访达中显示全路径">在访达中显示全路径</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.finder _FXShowPosixPathInTitle -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="取消隐藏用户文件夹">取消隐藏用户文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">chflags nohidden ~/Library
</code></pre></td></tr></table>
</div>
</div><h4 id="增加最近访问文件数量">增加最近访问文件数量</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g NSNavRecentPlacesLimit -int <span class="m">10</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h3 id="布局">布局</h3>
<h4 id="显示退出访达按钮">显示退出访达按钮</h4>
<p>显示 退出访达的默认快捷键是 <kbd>Cmd</kbd> + <kbd>Q</kbd> 。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.finder QuitMenuItem -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.finder QuitMenuItem -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h4 id="平滑滚动">平滑滚动</h4>
<p>对旧 Mac 会弄乱动画很有用。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write -g NSScrollAnimationEnabled -bool <span class="nb">false</span>

<span class="c1"># 关闭 (默认)</span>
defaults write -g NSScrollAnimationEnabled -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="橡皮筋滚动">橡皮筋滚动</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 禁止</span>
defaults write -g NSScrollViewRubberbanding -bool <span class="nb">false</span>

<span class="c1"># 关闭 (默认)</span>
defaults write -g NSScrollViewRubberbanding -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="展开默认保存面板">展开默认保存面板</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g NSNavPanelExpandedStateForSaveMode -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write -g NSNavPanelExpandedStateForSaveMode2 -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="桌面图标可见性">桌面图标可见性</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 掩藏图标</span>
defaults write com.apple.finder CreateDesktop -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder

<span class="c1"># 显示图标(默认)</span>
defaults write com.apple.finder CreateDesktop -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Finder
</code></pre></td></tr></table>
</div>
</div><h4 id="路径栏">路径栏</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 显示</span>
defaults write com.apple.finder ShowPathbar -bool <span class="nb">true</span>

<span class="c1"># 掩藏 (默认)</span>
defaults write com.apple.finder ShowPathbar -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="滚动条可见性">滚动条可见性</h4>
<p>可选的选项: <code>WhenScrolling</code> 、<code>Automatic</code> 和 <code>Always</code>。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g AppleShowScrollBars -string <span class="s2">&#34;Always&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="状态栏">状态栏</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 显示</span>
defaults write com.apple.finder ShowStatusBar -bool <span class="nb">true</span>

<span class="c1"># 掩藏 (默认)</span>
defaults write com.apple.finder ShowStatusBar -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="默认保存到磁盘">默认保存到磁盘</h4>
<p>设置默认保存地址是本地磁盘，而不是 iCloud 。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g NSDocumentSaveNewDocumentsToCloud -bool <span class="nb">false</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="当当前文件夹设置为默认搜索范围">当当前文件夹设置为默认搜索范围</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.finder FXDefaultSearchScope -string <span class="s2">&#34;SCcf&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="设置访达的默认文件夹">设置访达的默认文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.finder NewWindowTarget -string <span class="s2">&#34;PfLo&#34;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write com.apple.finder NewWindowTargetPath -string <span class="s2">&#34;file://</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="设置侧边栏图标大小">设置侧边栏图标大小</h4>
<p>将大小设置为中等大小。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g NSTableViewDefaultSizeMode -int <span class="m">2</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="元数据文件">元数据文件</h3>
<h4 id="禁止在网络卷创建元数据文件">禁止在网络卷创建元数据文件</h4>
<p>避免创建 <code>.DS_Store</code> 以及 AppleDouble 文件。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="禁止在-usb-卷创建元数据文件">禁止在 USB 卷创建元数据文件</h4>
<p>避免创建 <code>.DS_Store</code> 以及 AppleDouble 文件。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.desktopservices DSDontWriteUSBStores -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="打开文件">打开文件</h3>
<h4 id="改变访达的工作文件夹">改变访达的工作文件夹</h4>
<p>如果同时打开了多个窗口，选择最上面。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">cd</span> <span class="s2">&#34;</span><span class="k">$(</span>osascript -e <span class="s1">&#39;tell app &#34;Finder&#34; to POSIX path of (insertion location as alias)&#39;</span><span class="k">)</span><span class="s2">&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="打开-url">打开 URL</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">open https://github.com
</code></pre></td></tr></table>
</div>
</div><h4 id="打开文件-1">打开文件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">open README.md
</code></pre></td></tr></table>
</div>
</div><h4 id="打开应用程序">打开应用程序</h4>
<p>你可以加上 <code>-a</code> 打开应用程序。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">open -a <span class="s2">&#34;Google Chrome&#34;</span> https://github.com
</code></pre></td></tr></table>
</div>
</div><h4 id="打开文件夹">打开文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">open /path/to/folder/
</code></pre></td></tr></table>
</div>
</div><h4 id="打开当前文件夹">打开当前文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">open .
</code></pre></td></tr></table>
</div>
</div><h2 id="字体">字体</h2>
<h4 id="清空当前用户字体缓存">清空当前用户字体缓存</h4>
<p>为了清除所有用户的字体缓存，在命令前加上 <code>sudo</code>。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">atsutil databases -removeUser <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>atsutil server -shutdown <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>atsutil server -ping
</code></pre></td></tr></table>
</div>
</div><h4 id="获取-sf-mono-字体">获取 SF Mono 字体</h4>
<p>你需要先下载和安装 Xcode 8 beta，之后所有应用都可以使用。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">cp -v /Applications/Xcode-beta.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Fonts/SFMono-* ~/Library/Fonts
</code></pre></td></tr></table>
</div>
</div><p>对于 Sierra 之前的版本，它们包含 Terminal.app 中。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">cp -v /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/SFMono-* ~/Library/Fonts
</code></pre></td></tr></table>
</div>
</div><h2 id="函数">函数</h2>
<p>请看 <a href="/post/awesome-macos-command-line-zh/functions">这个文件</a>.</p>
<h2 id="硬件">硬件</h2>
<h3 id="蓝牙">蓝牙</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
defaults <span class="nb">read</span> /Library/Preferences/com.apple.Bluetooth ControllerPowerState

<span class="c1"># 开启 (默认)</span>
sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int <span class="m">1</span>

<span class="c1"># 禁止</span>
sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int <span class="m">0</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo killall -HUP blued
</code></pre></td></tr></table>
</div>
</div><h3 id="硬盘">硬盘</h3>
<h4 id="强制启用修剪">强制启用修剪</h4>
<p>从 Yosemite 开始,可以开启非苹果 SSD 的修剪。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">forcetrim
</code></pre></td></tr></table>
</div>
</div><h3 id="硬件信息">硬件信息</h3>
<h4 id="列出所有硬件端口">列出所有硬件端口</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">networksetup -listallhardwareports
</code></pre></td></tr></table>
</div>
</div><h4 id="剩余电池百分比">剩余电池百分比</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pmset -g batt <span class="p">|</span> egrep <span class="s2">&#34;([0-9]+\%).*&#34;</span> -o --colour<span class="o">=</span>auto <span class="p">|</span> cut -f1 -d<span class="s1">&#39;;&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="剩余电池时间">剩余电池时间</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pmset -g batt <span class="p">|</span> egrep <span class="s2">&#34;([0-9]+\%).*&#34;</span> -o --colour<span class="o">=</span>auto <span class="p">|</span> cut -f3 -d<span class="s1">&#39;;&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示已连接设备的-udid">显示已连接设备的 UDID</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">system_profiler SPUSBDataType <span class="p">|</span> sed -n -e <span class="s1">&#39;/iPad/,/Serial/p&#39;</span> -e <span class="s1">&#39;/iPhone/,/Serial/p&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示当前屏幕分辨率">显示当前屏幕分辨率</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">system_profiler SPDisplaysDataType <span class="p">|</span> grep Resolution
</code></pre></td></tr></table>
</div>
</div><h4 id="显示-cpu-品牌信息">显示 CPU 品牌信息</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sysctl -n machdep.cpu.brand_string
</code></pre></td></tr></table>
</div>
</div><h3 id="红外传感器">红外传感器</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
defaults <span class="nb">read</span> /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled

<span class="c1"># 开启 (默认)</span>
defaults write /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled -int <span class="m">1</span>

<span class="c1"># 关闭</span>
defaults write /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled -int <span class="m">0</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="电池管理">电池管理</h3>
<h4 id="禁止电脑休眠">禁止电脑休眠</h4>
<p>一小时内不使用不睡眠。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">caffeinate -u -t <span class="m">3600</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示所有电池设置">显示所有电池设置</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo pmset -g
</code></pre></td></tr></table>
</div>
</div><h4 id="15-分钟无活动后显示器睡眠">15 分钟无活动后显示器睡眠</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo pmset displaysleep <span class="m">15</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="30-分钟无活动后显示器睡眠">30 分钟无活动后显示器睡眠</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo pmset sleep <span class="m">30</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="检查系统睡眠剩余时间">检查系统睡眠剩余时间</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -getcomputersleep
</code></pre></td></tr></table>
</div>
</div><h4 id="将系统睡眠剩余时间设置为-60-分钟">将系统睡眠剩余时间设置为 60 分钟</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -setcomputersleep <span class="m">60</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="完全关闭系统睡眠">完全关闭系统睡眠</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -setcomputersleep Never
</code></pre></td></tr></table>
</div>
</div><h4 id="系统冻结时自动重启">系统冻结时自动重启</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -setrestartfreeze on
</code></pre></td></tr></table>
</div>
</div><h4 id="充电时显示铃声">充电时显示铃声</h4>
<p>当 MagSafe 连接时，播放 IOS 充电声音。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
defaults write com.apple.PowerChime ChimeOnAllHardware -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>open /System/Library/CoreServices/PowerChime.app

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.PowerChime ChimeOnAllHardware -bool <span class="nb">false</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall PowerChime
</code></pre></td></tr></table>
</div>
</div><h2 id="输入设备">输入设备</h2>
<h3 id="键盘">键盘</h3>
<h4 id="自动纠正">自动纠正</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 禁止</span>
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool <span class="nb">false</span>

<span class="c1"># 开启 (默认)</span>
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool <span class="nb">true</span>

<span class="c1"># 显示状态</span>
defaults <span class="nb">read</span> -g NSAutomaticSpellingCorrectionEnabled
</code></pre></td></tr></table>
</div>
</div><h4 id="全键盘访问">全键盘访问</h4>
<p>对话框启用 Tab 。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1">#  仅限文本框和列表 (默认)</span>
defaults write NSGlobalDomain AppleKeyboardUIMode -int <span class="m">0</span>

<span class="c1"># 所有控件</span>
defaults write NSGlobalDomain AppleKeyboardUIMode -int <span class="m">3</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="按键重复">按键重复</h4>
<p>禁止默认的 &ldquo;press and hold&rdquo; 行为。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启按键重复</span>
defaults write -g ApplePressAndHoldEnabled -bool <span class="nb">false</span>

<span class="c1"># 禁止按键重复</span>
defaults write -g ApplePressAndHoldEnabled -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="按键重复频率">按键重复频率</h4>
<p>设置非常快的按键频率，根据个人品味调整。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g KeyRepeat -int 0.02
</code></pre></td></tr></table>
</div>
</div><h2 id="启动台">启动台</h2>
<h4 id="重设启动台布局">重设启动台布局</h4>
<p>你需要重启程序坞，因为启动台与它紧密相连。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># Yosemite 之前的版本</span>
rm ~/Library/Application<span class="se">\ </span>Support/Dock/*.db <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock

<span class="c1"># El Capitan及以上的版本</span>
defaults write com.apple.dock ResetLaunchPad -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall Dock
</code></pre></td></tr></table>
</div>
</div><h2 id="媒体">媒体</h2>
<h3 id="音频">音频</h3>
<h4 id="将音频文件转换为-iphone-铃声">将音频文件转换为 iPhone 铃声。</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">afconvert input.mp3 ringtone.m4r -f m4af
</code></pre></td></tr></table>
</div>
</div><h4 id="从文本创建音频书">从文本创建音频书</h4>
<p>使用 <strong>Alex</strong> 声音，将单纯的 UTF-8 文本文件转换为 AAC。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">say -v Alex -f file.txt -o <span class="s2">&#34;output.m4a&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="开机禁用声音">开机禁用声音</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo nvram <span class="nv">SystemAudioVolume</span><span class="o">=</span><span class="s2">&#34; &#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="静音音频输出">静音音频输出</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">osascript -e <span class="s1">&#39;set volume output muted true&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="设置音量">设置音量</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">osascript -e <span class="s1">&#39;set volume 4&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="播放音频文件">播放音频文件</h4>
<p>你可以播放所有 QuickTime 支持的音频格式。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">afplay -q <span class="m">1</span> filename.mp3
</code></pre></td></tr></table>
</div>
</div><h4 id="使用系统默认声音讲述文本">使用系统默认声音讲述文本</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">say <span class="s1">&#39;All your base are belong to us!&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="视频">视频</h3>
<h4 id="quicktime-自动播放视频">QuickTime 自动播放视频</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen <span class="m">1</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="网络">网络</h2>
<h3 id="bonjour">Bonjour</h3>
<h4 id="bonjour-服务">Bonjour 服务</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 禁止</span>
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ProgramArguments -array-add <span class="s2">&#34;-NoMulticastAdvertisements&#34;</span>

<span class="c1"># 开启 (默认)</span>
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ProgramArguments -array <span class="s2">&#34;/usr/sbin/mDNSResponder&#34;</span> <span class="s2">&#34;-launchd&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="dhcp">DHCP</h3>
<h4 id="更新-dhcp-租约">更新 DHCP 租约</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo ipconfig <span class="nb">set</span> en0 DHCP
</code></pre></td></tr></table>
</div>
</div><h4 id="显示-dhcp-信息">显示 DHCP 信息</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">ipconfig getpacket en0
</code></pre></td></tr></table>
</div>
</div><h3 id="dns">DNS</h3>
<h4 id="清除-dns-缓存">清除 DNS 缓存</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo dscacheutil -flushcache <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo killall -HUP mDNSResponder
</code></pre></td></tr></table>
</div>
</div><h3 id="域名">域名</h3>
<h4 id="设置电脑域名">设置电脑域名</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo scutil --set ComputerName <span class="s2">&#34;newhostname&#34;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo scutil --set HostName <span class="s2">&#34;newhostname&#34;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo scutil --set LocalHostName <span class="s2">&#34;newhostname&#34;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string <span class="s2">&#34;newhostname&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="网络设置">网络设置</h3>
<h4 id="网络位置">网络位置</h4>
<p>在网络设置中切换网络位置。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
scselect

<span class="c1"># 切换网络位置</span>
scselect LocationNameFromStatus
</code></pre></td></tr></table>
</div>
</div><h4 id="设置静态-ip-地址">设置静态 IP 地址</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">networksetup -setmanual <span class="s2">&#34;Ethernet&#34;</span> 192.168.2.100 255.255.255.0 192.168.2.1
</code></pre></td></tr></table>
</div>
</div><h3 id="网络工具">网络工具</h3>
<h4 id="查看网络地址是否可以访问">查看网络地址是否可以访问</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">ping -o github.com
</code></pre></td></tr></table>
</div>
</div><h4 id="解决路由问题">解决路由问题</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">traceroute github.com
</code></pre></td></tr></table>
</div>
</div><h3 id="ssh">SSH</h3>
<h4 id="将私钥密码永久添加到-ssh-代理">将私钥密码永久添加到 SSH 代理</h4>
<blockquote>
<p>在 macOS Sierra 之前，ssh 会弹出输入密码的对话框，并提供是否将其存储到钥匙串的选项。 这个功能之后被删除。</p>
<p>在 macOS Sierra 中引入了 <strong>UseKeychain</strong> 选项，允许用户指定是否将密码存储在钥匙串中。 默认情况下，这个选项是开启的，这会导致所有密码都存储在钥匙串中。</p>
<p>这不是预期的默认行为，因此在 macOS 10.12.2 更改过来。（[来源]（https://developer.apple.com/library/archive/technotes/tn2449/_index.html））</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">ssh-add -K /path/to/private_key
</code></pre></td></tr></table>
</div>
</div><p>Then add to <code>~/.ssh/config</code>:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">Host server.example.com
    IdentityFile /path/to/private_key
    UseKeychain yes
</code></pre></td></tr></table>
</div>
</div><h4 id="远程登录">远程登录</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启远程登录</span>
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

<span class="c1"># 关闭远程登录</span>
sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
</code></pre></td></tr></table>
</div>
</div><h3 id="tcpip">TCP/IP</h3>
<h4 id="显示使用特定端口的应用程序">显示使用特定端口的应用程序</h4>
<p>输出所有使用 80 端口的应用程序。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo lsof -i :80
</code></pre></td></tr></table>
</div>
</div><h4 id="显示外部-ip-地址">显示外部 IP 地址</h4>
<p>仅当你的 ISP 没有替换 DNS 请求(一般不会)。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">dig +short myip.opendns.com @resolver1.opendns.com
</code></pre></td></tr></table>
</div>
</div><p>在所有网络中都可使用的替代方法。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">curl -s https://api.ipify.org <span class="o">&amp;&amp;</span> <span class="nb">echo</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="tftp">TFTP</h3>
<h4 id="启动原生的-tftp-daemon">启动原生的 TFTP Daemon</h4>
<p>文件将从 <code>/private/tftpboot</code> 启动。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo launchctl start com.apple.tftpd
</code></pre></td></tr></table>
</div>
</div><h3 id="wi-fi">Wi-Fi</h3>
<h4 id="加入-wi-fi-网络">加入 Wi-Fi 网络</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">networksetup -setairportnetwork en0 WIFI_SSID WIFI_PASSWORD
</code></pre></td></tr></table>
</div>
</div><h4 id="扫描可用的接入点">扫描可用的接入点</h4>
<p>创建 airport 轻松接入的符号链接。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport
</code></pre></td></tr></table>
</div>
</div><p>运行无线扫描：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">airport -s
</code></pre></td></tr></table>
</div>
</div><h4 id="显示当前的-ssid">显示当前的 SSID</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I <span class="p">|</span> awk <span class="s1">&#39;/ SSID/ {print substr($0, index($0, $2))}&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示本地-ip-地址">显示本地 IP 地址</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">ipconfig getifaddr en0
</code></pre></td></tr></table>
</div>
</div><h4 id="显示-wi-fi-的连接历史">显示 Wi-Fi 的连接历史</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults <span class="nb">read</span> /Library/Preferences/SystemConfiguration/com.apple.airport.preferences <span class="p">|</span> grep LastConnected -A <span class="m">7</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示-wi-fi-网络密码">显示 Wi-Fi 网络密码</h4>
<p>如果你希望使用 SSID 查询密码。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">security find-generic-password -D <span class="s2">&#34;AirPort network password&#34;</span> -a <span class="s2">&#34;SSID&#34;</span> -gw
</code></pre></td></tr></table>
</div>
</div><h4 id="开启-wi-fi-适配器">开启 Wi-Fi 适配器</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">networksetup -setairportpower en0 on
</code></pre></td></tr></table>
</div>
</div><h2 id="包管理器">包管理器</h2>
<ul>
<li><a href="http://www.finkproject.org">Fink</a> - Unix 开源软件的全部 Darwin 世界，有点过时。</li>
<li><a href="https://brew.sh">Homebrew</a> - OS X 缺少的包管理器，最流行的选择，我使用这个工具。</li>
<li><a href="https://www.macports.org">MacPorts</a> - 基于 X11 、Aqua 的开源软件，编译、安装和升级软件包命令行工具。 非常干净的工具，原作者使用它。</li>
</ul>
<h2 id="打印">打印</h2>
<h4 id="清除打印队列">清除打印队列</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">cancel -a -
</code></pre></td></tr></table>
</div>
</div><h4 id="默认展开打印面板">默认展开打印面板</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write -g PMPrintingExpandedStateForPrint -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>defaults write -g PMPrintingExpandedStateForPrint2 -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="打印完成后停止打印机">打印完成后停止打印机</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.print.PrintingPrefs <span class="s2">&#34;Quit When Finished&#34;</span> -bool <span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="安全">安全</h2>
<h3 id="应用防火墙">应用防火墙</h3>
<h4 id="防火墙服务">防火墙服务</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

<span class="c1"># 开启</span>
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on

<span class="c1"># 关闭 (默认)</span>
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
</code></pre></td></tr></table>
</div>
</div><h4 id="将应用添加到防火墙">将应用添加到防火墙</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /path/to/file
</code></pre></td></tr></table>
</div>
</div><h3 id="网关">网关</h3>
<h4 id="添加网关异常">添加网关异常</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">spctl --add /path/to/Application.app
</code></pre></td></tr></table>
</div>
</div><h4 id="删除网关异常">删除网关异常</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">spctl --remove /path/to/Application.app
</code></pre></td></tr></table>
</div>
</div><h4 id="管理网关">管理网关</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
spctl --status

<span class="c1"># 开启 (默认)</span>
sudo spctl --master-enable

<span class="c1"># 关闭</span>
sudo spctl --master-disable
</code></pre></td></tr></table>
</div>
</div><h3 id="密码">密码</h3>
<h4 id="产生安全的密码并且复制到剪贴板">产生安全的密码并且复制到剪贴板</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nv">LC_ALL</span><span class="o">=</span>C tr -dc <span class="s2">&#34;[:alnum:]&#34;</span> &lt; /dev/urandom <span class="p">|</span> head -c <span class="m">20</span> <span class="p">|</span> pbcopy
</code></pre></td></tr></table>
</div>
</div><h3 id="物理访问">物理访问</h3>
<h4 id="启动屏幕保护程序">启动屏幕保护程序</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># Sierra 之前</span>
open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app

<span class="c1"># Sierra 之后</span>
/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine
</code></pre></td></tr></table>
</div>
</div><h4 id="锁屏">锁屏</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">/System/Library/CoreServices/Menu<span class="se">\ </span>Extras/User.menu/Contents/Resources/CGSession -suspend
</code></pre></td></tr></table>
</div>
</div><h4 id="屏幕锁定">屏幕锁定</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
defaults <span class="nb">read</span> com.apple.screensaver askForPasswordDelay

<span class="c1"># 开启 (默认)</span>
defaults write com.apple.screensaver askForPasswordDelay -int <span class="m">0</span>

<span class="c1"># 禁止 (Integer = 锁屏的延迟秒数)</span>
defaults write com.apple.screensaver askForPasswordDelay -int <span class="m">10</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="屏幕保护密码">屏幕保护密码</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
defaults <span class="nb">read</span> com.apple.screensaver askForPassword

<span class="c1"># 开启</span>
defaults write com.apple.screensaver askForPassword -int <span class="m">1</span>

<span class="c1"># 关闭 (默认)</span>
defaults write com.apple.screensaver askForPassword -int <span class="m">0</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="擦除数据">擦除数据</h3>
<p>注意：在 MacOS 10.9 之后，<strong>srm</strong> 命令已经被删除了。 [Apple 支持页面]（https://support.apple.com/en-us/HT201949）解释了原因。</p>
<blockquote>
<p>使用 SSD 驱动器时，磁盘工具中不提供安全擦除和擦除可用空间功能。 SSD 驱动器不需要这些选项，因为标准擦除使得难以从 SSD 恢复数据。</p>
</blockquote>
<h4 id="安全删除文件">安全删除文件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">srm /path/to/file
</code></pre></td></tr></table>
</div>
</div><h4 id="安全删除文件夹">安全删除文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">srm -r /path/to/folder/
</code></pre></td></tr></table>
</div>
</div><h4 id="安全强制删除文件夹">安全强制删除文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">srm -rf /path/to/complete/destruction
</code></pre></td></tr></table>
</div>
</div><h2 id="搜索">搜索</h2>
<h3 id="查找">查找</h3>
<h4 id="递归删除-ds_store-文件">递归删除 .DS_Store 文件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">find . -type f -name <span class="s1">&#39;*.DS_Store&#39;</span> -ls -delete
</code></pre></td></tr></table>
</div>
</div><h3 id="定位">定位</h3>
<h4 id="建立定位数据库">建立定位数据库</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
</code></pre></td></tr></table>
</div>
</div><h4 id="通过定位查询">通过定位查询</h4>
<p><code>-i</code>修饰符意味着搜索对大小写敏感。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">locate -i *.jpg
</code></pre></td></tr></table>
</div>
</div><h2 id="系统">系统</h2>
<h3 id="airdrop">AirDrop</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 在 Ethernet 以上版本以及不支持的 Mac 版本，开启 AirDrop</span>
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool <span class="nb">true</span>

<span class="c1"># 开启 (默认)</span>
defaults remove com.apple.NetworkBrowser DisableAirDrop

<span class="c1"># 关闭</span>
defaults write com.apple.NetworkBrowser DisableAirDrop -bool YES
</code></pre></td></tr></table>
</div>
</div><h3 id="applescript">AppleScript</h3>
<h4 id="执行-applescript">执行 AppleScript</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">osascript /path/to/script.scpt
</code></pre></td></tr></table>
</div>
</div><h3 id="基础">基础</h3>
<h4 id="比较两个文件夹">比较两个文件夹</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">diff -qr /path/to/folder1 /path/to/folder2
</code></pre></td></tr></table>
</div>
</div><h4 id="复制较大文件显示进度条">复制较大文件显示进度条</h4>
<p>确定你已经安装了 <code>pv</code>，并且使用适当的写入设备或者文件替换了 <code>/dev/rdisk2</code>。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nv">FILE</span><span class="o">=</span>/path/to/file.iso pv -s <span class="k">$(</span>du -h <span class="nv">$FILE</span> <span class="p">|</span> awk <span class="s1">&#39;/.*/ {print $1}&#39;</span><span class="k">)</span> <span class="nv">$FILE</span> <span class="p">|</span> sudo dd <span class="nv">of</span><span class="o">=</span>/dev/rdisk2 <span class="nv">bs</span><span class="o">=</span>1m
</code></pre></td></tr></table>
</div>
</div><h4 id="修复疯狂-shell">修复疯狂 Shell</h4>
<p>如果你的 shell 会话疯狂。（比如某些脚本或应用程序将其变成乱码）。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">stty sane
</code></pre></td></tr></table>
</div>
</div><h4 id="重启">重启</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo reboot
</code></pre></td></tr></table>
</div>
</div><h4 id="关机">关机</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo poweroff
</code></pre></td></tr></table>
</div>
</div><h4 id="显示-os-版本信息">显示 OS 版本信息</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sw_vers
</code></pre></td></tr></table>
</div>
</div><h4 id="开机时间">开机时间</h4>
<p>显示上次开机到现在过去的时间。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">uptime
</code></pre></td></tr></table>
</div>
</div><h3 id="剪贴板">剪贴板</h3>
<h4 id="复制数据到剪贴板">复制数据到剪贴板</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">cat whatever.txt <span class="p">|</span> pbcopy
</code></pre></td></tr></table>
</div>
</div><h4 id="将剪贴板数据转换为纯文本">将剪贴板数据转换为纯文本</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pbpaste <span class="p">|</span> textutil -convert txt -stdin -stdout -encoding <span class="m">30</span> <span class="p">|</span> pbcopy
</code></pre></td></tr></table>
</div>
</div><h4 id="将剪贴板内容中的-tab-转换为空格">将剪贴板内容中的 Tab 转换为空格</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pbpaste <span class="p">|</span> expand <span class="p">|</span> pbcopy
</code></pre></td></tr></table>
</div>
</div><h4 id="复制剪贴板的数据">复制剪贴板的数据</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pbpaste &gt; whatever.txt
</code></pre></td></tr></table>
</div>
</div><h4 id="删除剪贴板重复内容以及排序">删除剪贴板重复内容以及排序</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">pbpaste <span class="p">|</span> sort <span class="p">|</span> uniq <span class="p">|</span> pbcopy
</code></pre></td></tr></table>
</div>
</div><h3 id="文件库">文件库</h3>
<h4 id="重启自动解锁文件库">重启自动解锁文件库</h4>
<p>如果在当前卷上启用了文件库，则会绕过初始解锁，重新启动系统。 该命令可能无法在所有版本上运行。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo fdesetup authrestart
</code></pre></td></tr></table>
</div>
</div><h4 id="文件库服务">文件库服务</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
sudo fdesetup status

<span class="c1"># 开启</span>
sudo fdesetup <span class="nb">enable</span>

<span class="c1"># 禁止 (默认)</span>
sudo fdesetup disable
</code></pre></td></tr></table>
</div>
</div><h3 id="信息报告">信息/报告</h3>
<h4 id="产生高级系统和性能报告">产生高级系统和性能报告</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo sysdiagnose -f ~/Desktop/
</code></pre></td></tr></table>
</div>
</div><h3 id="安装系统">安装系统</h3>
<h4 id="创建安装启动器">创建安装启动器</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># Mojave</span>
sudo /Applications/Install<span class="se">\ </span>macOS<span class="se">\ </span>Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --nointeraction --downloadassets

<span class="c1"># High Sierra</span>
sudo /Applications/Install<span class="se">\ </span>macOS<span class="se">\ </span>High<span class="se">\ </span>Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install<span class="se">\ </span>macOS<span class="se">\ </span>High<span class="se">\ </span>Sierra.app

<span class="c1"># Sierra</span>
sudo /Applications/Install<span class="se">\ </span>macOS<span class="se">\ </span>Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install<span class="se">\ </span>macOS<span class="se">\ </span>Sierra.app

<span class="c1"># El Capitan</span>
sudo /Applications/Install<span class="se">\ </span>OS<span class="se">\ </span>X<span class="se">\ </span>El<span class="se">\ </span>Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install<span class="se">\ </span>OS<span class="se">\ </span>X<span class="se">\ </span>El<span class="se">\ </span>Capitan.app

<span class="c1"># Yosemite</span>
sudo /Applications/Install<span class="se">\ </span>OS<span class="se">\ </span>X<span class="se">\ </span>Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install<span class="se">\ </span>OS<span class="se">\ </span>X<span class="se">\ </span>Yosemite.app
</code></pre></td></tr></table>
</div>
</div><ul>
<li>删除驱动器之前进行确认，删去 <code>--nointeraction</code> 选项。</li>
<li>Mojave 中才可以使用 <code>--downloadassets</code> 选项。 安装过程中可能会下载资源，比如更新。</li>
<li>从 Mojave 开始，<code>--applicationpath</code> 选项以及被废弃。使用该选项会抛出错误。</li>
</ul>
<h3 id="内核扩展">内核扩展</h3>
<h4 id="展示加载的内核扩展">展示加载的内核扩展</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo kextstat -l
</code></pre></td></tr></table>
</div>
</div><h4 id="加载内核扩展">加载内核扩展</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo kextload -b com.apple.driver.ExampleBundle
</code></pre></td></tr></table>
</div>
</div><h4 id="卸载内核扩展">卸载内核扩展</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo kextunload -b com.apple.driver.ExampleBundle
</code></pre></td></tr></table>
</div>
</div><h3 id="自启动服务">自启动服务</h3>
<p>请看 <a href="/post/awesome-macos-command-line-zh/launchagents">自启动服务</a>.</p>
<h3 id="自启动服务-1">自启动服务</h3>
<h4 id="重建自启动服务数据库">重建自启动服务数据库</h4>
<p>为了做到与 OS X 版本无关，这个工具依赖 <code>locate</code> 查找 <code>lsregister</code>。 如果你还没有建立你的 <code>locate</code> 数据库，<a href="#%E5%88%9B%E5%BB%BA%E5%AE%9A%E4%BD%8D%E6%95%B0%E6%8D%AE%E5%BA%93">请先创建</a>。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo <span class="k">$(</span>locate lsregister<span class="k">)</span> -kill -seed -r
</code></pre></td></tr></table>
</div>
</div><h3 id="登录窗口">登录窗口</h3>
<h4 id="设置登录窗口文本">设置登录窗口文本</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText <span class="s2">&#34;Your text&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="内存管理">内存管理</h3>
<h4 id="清除内存缓存">清除内存缓存</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo purge
</code></pre></td></tr></table>
</div>
</div><h4 id="显示内存统计">显示内存统计</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># One time</span>
vm_stat

<span class="c1"># Table of data, repeat 10 times total, 1 second wait between each poll</span>
vm_stat -c <span class="m">10</span> <span class="m">1</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="通知中心">通知中心</h3>
<h4 id="通知中心服务">通知中心服务</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 关闭</span>
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall -9 NotificationCenter

<span class="c1"># 启动 (默认)</span>
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
</code></pre></td></tr></table>
</div>
</div><h3 id="快速浏览">快速浏览</h3>
<h4 id="快速浏览文件">快速浏览文件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">qlmanage -p /path/to/file
</code></pre></td></tr></table>
</div>
</div><h3 id="远程苹果事件">远程苹果事件</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
sudo systemsetup -getremoteappleevents

<span class="c1"># 开启</span>
sudo systemsetup -setremoteappleevents on

<span class="c1"># 禁止 (默认)</span>
sudo systemsetup -setremoteappleevents off
</code></pre></td></tr></table>
</div>
</div><h3 id="root-用户">Root 用户</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 开启</span>
dsenableroot

<span class="c1"># 禁止</span>
dsenableroot -d
</code></pre></td></tr></table>
</div>
</div><h3 id="安全模式启动">安全模式启动</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
nvram boot-args

<span class="c1"># 开启</span>
sudo nvram boot-args<span class="o">=</span><span class="s2">&#34;-x&#34;</span>

<span class="c1"># 禁止</span>
sudo nvram boot-args<span class="o">=</span><span class="s2">&#34;&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="截图">截图</h3>
<h4 id="延迟截图">延迟截图</h4>
<p>3 秒后截图为 JPEG 文件，并且在预览中展示。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">screencapture -T <span class="m">3</span> -t jpg -P delayedpic.jpg
</code></pre></td></tr></table>
</div>
</div><h4 id="保存截图到给定位置">保存截图到给定位置</h4>
<p>设置保存地址为桌面。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.screencapture location ~/Desktop <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall SystemUIServer
</code></pre></td></tr></table>
</div>
</div><h4 id="设置截图文件格式">设置截图文件格式</h4>
<p>设置截图文件格式为 <code>png</code>，可选的格式有 <code>bmp</code>, <code>gif</code>, <code>jpg</code>, <code>jpeg</code>, <code>pdf</code>, <code>tiff</code> 。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.screencapture <span class="nb">type</span> -string <span class="s2">&#34;png&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="禁止截图阴影">禁止截图阴影</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.screencapture disable-shadow -bool <span class="nb">true</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall SystemUIServer
</code></pre></td></tr></table>
</div>
</div><h4 id="设置截图的默认文件名">设置截图的默认文件名</h4>
<p>截图文件名的时间戳保持不变。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.screencapture name <span class="s2">&#34;Example name&#34;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>killall SystemUIServer
</code></pre></td></tr></table>
</div>
</div><h3 id="软件安装">软件安装</h3>
<h4 id="安装-pkg">安装 PKG</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">installer -pkg /path/to/installer.pkg -target /
</code></pre></td></tr></table>
</div>
</div><h3 id="软件更新">软件更新</h3>
<h4 id="更新所有可以更新的软件">更新所有可以更新的软件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo softwareupdate -ia
</code></pre></td></tr></table>
</div>
</div><h4 id="设置软件更新检查的时间间隔">设置软件更新检查的时间间隔</h4>
<p>将软件更新检查的时间间隔设置为天，而不是默认的周。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">defaults write com.apple.SoftwareUpdate ScheduleFrequency -int <span class="m">1</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示所有可以更新的软件">显示所有可以更新的软件</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo softwareupdate -l
</code></pre></td></tr></table>
</div>
</div><h4 id="设置软件更新服务器">设置软件更新服务器</h4>
<p>这仅适用于测试或非托管的客户端。 要在网络范围内使用，请正确设置 DNS 以及 <a href="http://krypted.com/mac-security/using-the-software-update-service-on-mountain-lion-server/">Apple SUS 服务</a> 并通过 OpenDirectory 绑定客户端。 或者，使用 <a href="https://github.com/wdas/reposado">Reposado</a> 正确设置网络 DNS，使分辨率变得透明。 <a href="https://github.com/jessepeterson/margarita">Margarita</a> 看起来也不错。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 使用自己 SUS</span>
sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://su.example.com:8088/index.sucatalog

<span class="c1"># 恢复苹果的默认 SUS</span>
sudo defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL
</code></pre></td></tr></table>
</div>
</div><h3 id="软件版本">软件版本</h3>
<h4 id="显示系统的版本号">显示系统的版本号</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sw_vers -productVersion
</code></pre></td></tr></table>
</div>
</div><h3 id="聚焦">聚焦</h3>
<h4 id="聚焦索引">聚焦索引</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 禁止</span>
mdutil -i off -d /path/to/volume

<span class="c1"># 关闭 (默认)</span>
mdutil -i on /path/to/volume
</code></pre></td></tr></table>
</div>
</div><h4 id="擦除聚焦索引并重建">擦除聚焦索引并重建</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">mdutil -E /path/to/volume
</code></pre></td></tr></table>
</div>
</div><h4 id="通过聚焦搜索">通过聚焦搜索</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">mdfind -name <span class="s1">&#39;searchterm&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="显示聚焦索引元数据">显示聚焦索引元数据</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">mdls /path/to/file
</code></pre></td></tr></table>
</div>
</div><h3 id="系统完整性保护">系统完整性保护</h3>
<h4 id="禁止系统完整性保护">禁止系统完整性保护</h4>
<p>按住 <kbd>Cmd</kbd> + <kbd>R</kbd> 重启，打开终端输入以下命令：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">csrutil disable <span class="o">&amp;&amp;</span> reboot
</code></pre></td></tr></table>
</div>
</div><h4 id="开启系统完整性保护">开启系统完整性保护</h4>
<p>按住 <kbd>Cmd</kbd> + <kbd>R</kbd> 重启，打开终端输入以下命令：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">csrutil <span class="nb">enable</span> <span class="o">&amp;&amp;</span> reboot
</code></pre></td></tr></table>
</div>
</div><h3 id="时间和日期">时间和日期</h3>
<h4 id="列出所有时区">列出所有时区</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -listtimezones
</code></pre></td></tr></table>
</div>
</div><h4 id="设置时区">设置时区</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">sudo systemsetup -settimezone Europe/Berlin
</code></pre></td></tr></table>
</div>
</div><h4 id="网络时间设置时钟">网络时间设置时钟</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 查看状态</span>
sudo systemsetup getusingnetworktime

<span class="c1"># 开启 (默认)</span>
sudo systemsetup setusingnetworktime on

<span class="c1"># 关闭</span>
sudo systemsetup setusingnetworktime off
</code></pre></td></tr></table>
</div>
</div><h2 id="终端-1">终端</h2>
<h4 id="终端响铃">终端响铃</h4>
<p>开启终端响铃，并在其上显示徽标数。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">tput bel
</code></pre></td></tr></table>
</div>
</div><h3 id="替代终端">替代终端</h3>
<ul>
<li><a href="https://iterm2.com">iTerm2</a> - 更好的终端应用</li>
<li><a href="https://sw.kovidgoyal.net/kitty/">kitty</a> - 现代化以及 GPU 加速的终端应用。</li>
</ul>
<h3 id="shells">Shells</h3>
<h4 id="bash">Bash</h4>
<p>安装最新版本的 Bash，并且设置为用户的默认的 shell</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">brew install bash <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span><span class="nb">echo</span> <span class="k">$(</span>brew --prefix<span class="k">)</span>/bin/bash <span class="p">|</span> sudo tee -a /etc/shells <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>chsh -s <span class="k">$(</span>brew --prefix<span class="k">)</span>/bin/bash
</code></pre></td></tr></table>
</div>
</div><ul>
<li><a href="https://www.gnu.org/software/bash/">Homepage</a> - OS X 以及 Unix 类似系统的默认 shell 。</li>
<li><a href="https://github.com/Bash-it/bash-it">Bash-it</a> - 社区驱动 Bash 框架，类似 Oh My Zsh</li>
</ul>
<h4 id="fish">fish</h4>
<p>安装最新版本的 fish，并且设置为用户的默认的 shell</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">brew install fish <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span><span class="nb">echo</span> <span class="k">$(</span>brew --prefix<span class="k">)</span>/bin/fish <span class="p">|</span> sudo tee -a /etc/shells <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>chsh -s <span class="k">$(</span>brew --prefix<span class="k">)</span>/bin/fish
</code></pre></td></tr></table>
</div>
</div><ul>
<li><a href="http://fishshell.com">Homepage</a> - 一个对 OS X 、Linux 用户友好的智能 shell,支持更多系统。</li>
<li><a href="https://github.com/oh-my-fish/oh-my-fish">The Fishshell Framework</a> - 提供核心基础结构，允许您扩展或修改 shell 外观的软件包。</li>
<li><a href="https://github.com/ellerbrock/fish-shell-setup-osx">Installation &amp; Configuration Tutorial</a> - 怎样通过 Fisherman、Powerline Fonts、 iTerm2 和 Budspencer Theme 安装 Fish Shell。</li>
</ul>
<h4 id="zsh">Zsh</h4>
<p>安装最新版本的 Zsh，并且设置为用户的默认的 shell</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">brew install zsh <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>sudo sh -c <span class="s1">&#39;echo $(brew --prefix)/bin/zsh &gt;&gt; /etc/shells&#39;</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span><span class="se"></span>chsh -s <span class="k">$(</span>brew --prefix<span class="k">)</span>/bin/zsh
</code></pre></td></tr></table>
</div>
</div><ul>
<li><a href="http://www.zsh.org">Homepage</a> - 尽管 Zsh 是一种强大的脚本语言，它是专为交互式使用而设计的 shell。</li>
<li><a href="http://ohmyz.sh">Oh My Zsh</a> - 社区驱动开源框架，用于管理 Zsh 配置。</li>
<li><a href="https://github.com/sorin-ionescu/prezto">Prezto</a> - 一个快速的 Zsh 框架。 使用默认值，别名，函数，自动完成和主题来丰富命令行界面环境。</li>
<li><a href="https://github.com/tarjoilija/zgen">zgen</a> - 另一个管理 Zsh 配置的开源框架。 Zgen 可以兼容 oh-my-zsh 的插件和主题，并且具有自动克隆任何插件以及更快的优点。</li>
</ul>
<h3 id="终端字体">终端字体</h3>
<ul>
<li><a href="http://www.marksimonson.com/fonts/view/anonymous-pro">Anonymous Pro</a> - 四种固定宽度系列字体，适用于编程。</li>
<li><a href="https://github.com/chrissimpkins/codeface">Codeface</a> - 用于开发人员的图库和等宽字体库。</li>
<li><a href="https://dejavu-fonts.github.io/">DejaVu Sans Mono</a> - 基于 Vera Fonts 的字体家族。</li>
<li><a href="http://sourcefoundry.org/hack/">Hack</a> - Hack 手动整理字体，是你编程字体的首选。</li>
<li><a href="http://levien.com/type/myfonts/inconsolata.html">Inconsolata</a> - 一种等宽字体，专为编程设计。</li>
<li><a href="http://input.fontbureau.com">Input</a> - 专为编程响应系统的字体设计。</li>
<li><a href="https://github.com/andreberg/Meslo-Font">Meslo</a> - Apple&rsquo;s Menlo 字体的自制版本.</li>
<li><a href="https://www.typography.com/fonts/operator/overview/">Operator Mono</a> - 令人惊讶的商业等宽字体。</li>
<li><a href="https://github.com/powerline/fonts">Powerline Fonts</a> - Powerline 插件的修补字体仓库</li>
<li><a href="https://adobe-fonts.github.io/source-code-pro/">Source Code Pro</a> - 专为用户交互以及编程的等宽字体家族。</li>
</ul>
<h2 id="词汇表">词汇表</h2>
<h3 id="mac-os-xos-x-以及-macos-的版本信息">Mac OS X、OS X 以及 macOS 的版本信息</h3>
<table>
<thead>
<tr>
<th>版本</th>
<th>名称</th>
<th>发布日期</th>
<th>最新版本</th>
</tr>
</thead>
<tbody>
<tr>
<td>Rhapsody Developer Release</td>
<td>Grail1Z4 / Titan1U</td>
<td>August 31, 1997</td>
<td>DR2 (May 14, 1998)</td>
</tr>
<tr>
<td>Mac OS X Server 1.0</td>
<td>Hera</td>
<td>March 16, 1999</td>
<td>1.2v3 (October 27, 2000)</td>
</tr>
<tr>
<td>Mac OS X Developer Preview</td>
<td>n/a</td>
<td>March 16, 1999</td>
<td>DP4 (April 5, 2000)</td>
</tr>
<tr>
<td>Mac OS X Public Beta</td>
<td>Kodiak</td>
<td>September 13, 2000</td>
<td>n/a</td>
</tr>
<tr>
<td>Mac OS X 10.0</td>
<td>Cheetah</td>
<td>March 24, 2001</td>
<td>10.0.4 (June 22, 2001)</td>
</tr>
<tr>
<td>Mac OS X 10.1</td>
<td>Puma</td>
<td>September 25, 2001</td>
<td>10.1.5 (June 6, 2002)</td>
</tr>
<tr>
<td>Mac OS X 10.2</td>
<td>Jaguar</td>
<td>August 24, 2002</td>
<td>10.2.8 (October 3, 2003)</td>
</tr>
<tr>
<td>Mac OS X 10.3</td>
<td>Panther</td>
<td>October 24, 2003</td>
<td>10.3.9 (April 15, 2005)</td>
</tr>
<tr>
<td>Mac OS X 10.4</td>
<td>Tiger</td>
<td>April 29, 2005</td>
<td>10.4.11 (November 14, 2007)</td>
</tr>
<tr>
<td>Mac OS X 10.5</td>
<td>Leopard</td>
<td>October 26, 2007</td>
<td>10.5.8 (August 5, 2009)</td>
</tr>
<tr>
<td>Mac OS X 10.6</td>
<td>Snow Leopard</td>
<td>August 28, 2009</td>
<td>10.6.8 v1.1 (July 25, 2011)</td>
</tr>
<tr>
<td>Mac OS X 10.7</td>
<td>Lion</td>
<td>July 20, 2011</td>
<td>10.7.5 (September 19, 2012)</td>
</tr>
<tr>
<td>OS X 10.8</td>
<td>Mountain Lion</td>
<td>July 25, 2012</td>
<td>10.8.5 (12F45) (October 3, 2013)</td>
</tr>
<tr>
<td>OS X 10.9</td>
<td>Mavericks</td>
<td>October 22, 2013</td>
<td>10.9.5 (13F1112) (September 18, 2014)</td>
</tr>
<tr>
<td>OS X 10.10</td>
<td>Yosemite</td>
<td>October 16, 2014</td>
<td>10.10.5 (14F27) (August 13, 2015)</td>
</tr>
<tr>
<td>OS X 10.11</td>
<td>El Capitan</td>
<td>September 30, 2015</td>
<td>10.11.6 (15G31) (July 18, 2016)</td>
</tr>
<tr>
<td>macOS 10.12</td>
<td>Sierra</td>
<td>September 20, 2016</td>
<td>10.12.6 (16G29) (July 19, 2017)</td>
</tr>
<tr>
<td>macOS 10.13</td>
<td>High Sierra</td>
<td>September 25, 2017</td>
<td>10.13.6 (17G65) (July 9, 2018)</td>
</tr>
<tr>
<td>macOS 10.14</td>
<td>Mojave</td>
<td>September 24, 2018</td>
<td>10.14 (18A391) (September 24, 2018)</td>
</tr>
</tbody>
</table>

  </div>

  <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">早起的年轻人</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2019-05-01 14:25
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a target="_blank" rel="license noopener" href="https://github.com/nusr/blog/blob/master/LICENSE">MIT</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/images/wechat.jpg">
        <span>微信佛系打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/images/alipay.jpg">
        <span>支付宝佛系打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
    <div class="post-tags">
      <a href="/tags/Awesome/">Awesome</a>
      </div>
    <nav class="post-nav">
      <a class="prev" href="/post/awesome-macos-command-line-zh/glossary/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default"> Mac OS 版本信息</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
      <a class="next" href="/post/awesome-macos-command-line-zh/entry/">
        <span class="next-text nav-default">Awesome Mac OS Command Line 中文翻译</span>
        <span class="next-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    </nav>
  </footer>
  
</article>
            </div>
            

        </div>
    </main>

    <footer id="footer" class="footer">
        <div class="social-links">
  <a href="852851198@qq.com" class="iconfont icon-email" title="email" rel="noopener" target="_blank" data-title="email"> </a>
  <a href="https://github.com/ITmxs" class="iconfont icon-github" title="github" rel="noopener" target="_blank" data-title="github"> </a>
  <a href="https://juejin.cn/user/3843548384077192" class="iconfont icon-juejin" title="juejin" rel="noopener" target="_blank" data-title="juejin"> </a>
  <a href="https://www.zhihu.com/people/yimi-yang-guang-96-65" class="iconfont icon-zhihu" title="zhihu" rel="noopener" target="_blank" data-title="zhihu"> </a>
  <a href="https://space.bilibili.com/480883651" class="iconfont icon-bilibili" title="bilibili" rel="noopener" target="_blank" data-title="bilibili"> </a>
  <a href="https://luckly.work/index.xml" type="application/rss+xml" rel="noopener" target="_blank" class="iconfont icon-rss" title="rss"></a>


</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  <div class="busuanzi-footer">
    <span id="busuanzi_container_site_pv"> 本站总访问量 <span id="busuanzi_value_site_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次 </span>
    <span class="division">|</span>
    <span id="busuanzi_container_site_uv"> 本站总访客数 <span id="busuanzi_value_site_uv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 人 </span>
  </div>

  <span class="copyright-year">
    &copy;
    2020 -
    2021
    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">早起的年轻人</span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
    </div>
</div>

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/timeago.js@3.0.2/dist/timeago.min.js" integrity="sha256-jwCP0NAdCBloaIWTWHmW4i3snUNMHUNO+jr9rYd2iOI=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/timeago.js@3.0.2/dist/timeago.locales.min.js" integrity="sha256-ZwofwC1Lf/faQCzN7nZtfijVV6hSwxjQMwXL4gn9qU8=" crossorigin="anonymous"></script>
  <script><!-- NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive) -->
    var languageCode = "zh-CN".replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());});
    timeago().render(document.querySelectorAll('.timeago'), languageCode);
    timeago.cancel();  
  </script>
<script type="text/javascript" src="/dist/even.47f727f4.min.js"></script>


<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-138883536-1', 'auto');
	ga('set', 'anonymizeIp', true);
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>







</body>
</html>
